package com.iss.wyy.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Properties;

public class PropertiesUtil {
    /**
     * 获取Properties
     * @param propertiesName
     * @return
     */
    public static Properties loadProperties(String propertiesName) {
        Properties properties = new Properties();
        // 使用ClassLoader加载properties配置文件生成对应的输入流
        InputStream in = ClassUtil.getClassLoader().getResourceAsStream(propertiesName);
        // 使用properties对象加载输入流
        try {
            properties.load(new InputStreamReader(in, "utf-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }

    /**
     * 读取配置文件的值
     * @param properties
     * @param key
     * @param defaltValue
     * @return
     */
    public static String getString(Properties properties,String key,String defaltValue){
        return properties.getProperty(key,defaltValue);
    }

    /**
     * 读取配置文件的值
     * @param properties
     * @param key
     * @return
     */
    public static String getString(Properties properties,String key){
        return getString(properties,key,null);
    }
}
